package com.dp.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dp.common.annotation.Log;
import com.dp.common.core.controller.BaseController;
import com.dp.common.core.domain.AjaxResult;
import com.dp.common.enums.BusinessType;
import com.dp.system.domain.SysGreenhouse;
import com.dp.system.service.ISysGreenhouseService;
import com.dp.common.utils.poi.ExcelUtil;
import com.dp.common.core.page.TableDataInfo;

/**
 * 大棚Controller
 * 
 * @author ruoyi
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/system/greenhouse")
public class SysGreenhouseController extends BaseController
{
    @Autowired
    private ISysGreenhouseService sysGreenhouseService;

    /**
     * 查询大棚列表
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGreenhouse sysGreenhouse)
    {
        startPage();
        List<SysGreenhouse> list = sysGreenhouseService.selectSysGreenhouseList(sysGreenhouse);
        return getDataTable(list);
    }

    /**
     * 导出大棚列表
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:export')")
    @Log(title = "大棚", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGreenhouse sysGreenhouse)
    {
        List<SysGreenhouse> list = sysGreenhouseService.selectSysGreenhouseList(sysGreenhouse);
        ExcelUtil<SysGreenhouse> util = new ExcelUtil<SysGreenhouse>(SysGreenhouse.class);
        util.exportExcel(response, list, "大棚数据");
    }

    /**
     * 获取大棚详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:query')")
    @GetMapping(value = "/{greenhouseId}")
    public AjaxResult getInfo(@PathVariable("greenhouseId") Long greenhouseId)
    {
        return success(sysGreenhouseService.selectSysGreenhouseByGreenhouseId(greenhouseId));
    }

    /**
     * 新增大棚
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:add')")
    @Log(title = "大棚", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGreenhouse sysGreenhouse)
    {
        return toAjax(sysGreenhouseService.insertSysGreenhouse(sysGreenhouse));
    }

    /**
     * 修改大棚
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:edit')")
    @Log(title = "大棚", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGreenhouse sysGreenhouse)
    {
        return toAjax(sysGreenhouseService.updateSysGreenhouse(sysGreenhouse));
    }

    /**
     * 删除大棚
     */
    @PreAuthorize("@ss.hasPermi('system:greenhouse:remove')")
    @Log(title = "大棚", businessType = BusinessType.DELETE)
	@DeleteMapping("/{greenhouseIds}")
    public AjaxResult remove(@PathVariable Long[] greenhouseIds)
    {
        return toAjax(sysGreenhouseService.deleteSysGreenhouseByGreenhouseIds(greenhouseIds));
    }
}
